package com.example.helloword.controller;

import lombok.NoArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;

/**
 * @create 2022-03-2022/3/10-16:41
 */
@NoArgsConstructor
@Controller
public class LoginController {
    @RequestMapping("/show")
    public String login(@RequestParam("username") String username, @RequestParam("password")String password, Model model, HttpSession session){
        if(!username.isEmpty()&& "1234".equals(password)){
            session.setAttribute("now_username",username);
            return "redirect:/show.html";
        }else {
            model.addAttribute("msg","用户名或密码错误");
            return "index";
        }
    }

    @RequestMapping("/logout")
    public String loginout(HttpSession session){
        session.invalidate();
        return "index";
    }

}
